package ctn.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ctn.convert.CPASpecCovert;
import ctn.dao.inteface.CPAInfoDao;
import ctn.dao.inteface.CPAVerDao;
import ctn.dao.inteface.SpecDao;
import ctn.hibernate.po.CpaFun;
import ctn.hibernate.po.CtnCpaSpec;
import ctn.hibernate.po.CtnCpaVer;
import ctn.service.dto.SpecDTO;
import ctn.service.inteface.SpecService;
import ctn.util.CPAUtil;
import ctn.util.jmesa.PaginationCriteria;
@Service
@Transactional
public class SpecServiceImpl implements SpecService {
	@Autowired
	private SpecDao specDaoImpl;
	@Autowired
	private CPAInfoDao cPAInfoDaoImpl;
	@Autowired
	private CPAVerDao cPAVerDaoImpl;
	@Autowired
	private CPAUtil cpaUtil;
	@Override
	public List<SpecDTO> getListSpec(PaginationCriteria criteria) {
		List<SpecDTO> dtos=new ArrayList<SpecDTO>();
		List<CtnCpaSpec> list=specDaoImpl.getListSpec(criteria);
		for(CtnCpaSpec po:list){
			SpecDTO dto=new SpecDTO();
			CPASpecCovert.convertPo2DTO(po, dto);
			dtos.add(dto);
		}
		return dtos;
	}

	@Override
	public Long getListSpecCount(PaginationCriteria criteria) {
		// TODO Auto-generated method stub
		return specDaoImpl.getListSpecCount(criteria);
	}

	@Override
	public String getFilePath(String id) {
		String filePath=specDaoImpl.getSpecFilePath(id);
		return filePath;
	}

	@Override
	public CtnCpaSpec getSpecByCapVerFun(Long verID, Long funId) {
		CtnCpaSpec spec=new CtnCpaSpec();
		CtnCpaVer ver=cPAVerDaoImpl.queryVer(verID);
		spec.setCtnCpaVer(ver);
		if(funId!=null){
			CpaFun fun=cPAInfoDaoImpl.getCpaFunByID(String.valueOf(funId));
			spec.setCpaFun(fun);
		}
		CtnCpaSpec rtnSpec=specDaoImpl.getCpaSpecByExample(spec);
		return rtnSpec;
	}

	@Override
	public void saveSpec(SpecDTO specDTO) {
		// TODO Auto-generated method stub
		
	}

}
